<?php
// +---------------------------------------------------------------------+
// | OneBase    | [ WE CAN DO IT JUST THINK ]                            |
// +---------------------------------------------------------------------+
// | Licensed   | http://www.apache.org/licenses/LICENSE-2.0 )           |
// +---------------------------------------------------------------------+
// | Author     | Bigotry <3162875@qq.com>                               |
// +---------------------------------------------------------------------+
// | Repository | https://gitee.com/Bigotry/OneBase                      |
// +---------------------------------------------------------------------+

namespace app\common\logic;

/**
 * version逻辑
 */
class Version extends LogicBase
{
    

    
    /**
     * 获取version列表
     */
    public function getversionList($where = [], $field = 'a.*', $order = '')
    {
        
        $this->modelversion->alias('a');
        

        
        $where['a.' . DATA_STATUS_NAME] = ['neq', DATA_DELETE];

        return $this->modelversion->getList($where, $field, $order);
    }
    
    /**
     * 获取version列表搜索条件
     */
    public function getWhere($data = [])
    {
        
        $where = [];
        
        !empty($data['search_data']) && $where['a.title'] = ['like', '%'.$data['search_data'].'%'];
        
        return $where;
    }
    
    /**
     * version信息编辑
     */
    public function versionEdit($data = [])
    {

        $validate_result = $this->validateversion->scene('edit')->check($data);
        
        if (!$validate_result) {
            
            return [RESULT_ERROR, $this->validateversion->getError()];
        }
        if(!isset($data['is_enable'])){
            $data['is_enable']=0;
        }
        $url = url('versionList');

        if(!empty($data['start_time'])  && !empty($data['end_time'])){
            $data['start_time']=strtotime($data['start_time'].' 00:00:00');
            $data['end_time']=strtotime($data['end_time'].' 23:59:59');
        }
        
        $result = $this->modelversion->setInfo($data);

        $handle_text = empty($data['id']) ? '新增' : '编辑';

        
        $result && action_log($handle_text, 'version' . $handle_text . '，title：' . $data['title']);
        
        return $result ? [RESULT_SUCCESS, 'version操作成功', $url] : [RESULT_ERROR, $this->modelversion->getError()];
    }

    /**
     * 获取version信息
     */
    public function getversionInfo($where = [], $field = 'a.*')
    {
        
        $this->modelversion->alias('a');
        

        $where['a.' . DATA_STATUS_NAME] = ['neq', DATA_DELETE];
        
        return $this->modelversion->getInfo($where, $field);
    }
    


    /**

    
    /**
     * version删除
     */
    public function versionDel($where = [])
    {
        
        $result = $this->modelversion->deleteInfo($where);
        
        $result && action_log('删除', 'version删除，where：' . http_build_query($where));
        
        return $result ? [RESULT_SUCCESS, 'version删除成功'] : [RESULT_ERROR, $this->modelversion->getError()];
    }
}
